package explorer;

import java.awt.Color;
import java.awt.Desktop;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.io.IOException;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class ElementsController implements MouseListener{

	private JPanel panel;
	private File content;
	private PathLoader folder;
	
	public ElementsController(JPanel panel, File content) {
		super();
		this.panel = panel;
		this.content=content;
	}
	
	
	
	@Override
	public void mouseClicked(MouseEvent e) {
		
		if(e.getClickCount()==2){
			if (content.isDirectory()==true){
				
				folder=new PathLoader(content);
				
								
			}else{			
				try {
					Desktop.getDesktop().open(content);
				} catch (IOException e1) {
			
					JFrame frame= new JFrame();
					JOptionPane.showMessageDialog(frame, "Opening Error!", "Attention!", JOptionPane.WARNING_MESSAGE);
			
			// TODO Auto-generated catch block
			//e1.printStackTrace();
				}
			}
		}else if(e.getClickCount()==1){
			panel.setBackground(Color.RED);
		}
		
	}@Override
	public void mouseEntered(MouseEvent e) {
		panel.setBackground(Color.LIGHT_GRAY);
		
	}@Override
	public void mouseExited(MouseEvent e) {
		panel.setBackground(null);
		
	}@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	
}
